﻿using System.Collections.Generic;

namespace GameLogger
{
    /// <summary>
    /// GameLogger模块
    /// </summary>
    public static class Module
    {
        private static List<ILogger> allLogger = new List<ILogger>(8);

        private static bool sEnableLogLevelDebug = true;
        private static bool sEnableLogLevelInfo = true;

        /// <summary>
        /// 新建Unity日志输出器
        /// </summary>
        /// <param name="moduleName"></param>
        /// <param name="enableDebug"></param>
        /// <param name="enableInfo"></param>
        /// <param name="outputModuleName"></param>
        /// <param name="outputTime"></param>
        /// <param name="acOutputDebug"></param>
        /// <param name="acOutputInfo"></param>
        /// <param name="acOutputWarning"></param>
        /// <param name="acOutputError"></param>
        /// <param name="acOutputException"></param>
        /// <returns></returns>
        public static ILogger NewUnityLogger(string moduleName, bool enableDebug, bool enableInfo, bool outputModuleName, bool outputTime,
            System.Action<System.Object> acOutputDebug,
            System.Action<System.Object> acOutputInfo,
            System.Action<System.Object> acOutputWarning,
            System.Action<System.Object> acOutputError,
            System.Action<System.Exception> acOutputException)
        {
            var logger = new LoggerUnity(moduleName, sEnableLogLevelDebug && enableDebug, sEnableLogLevelInfo && enableInfo, outputModuleName, outputTime,
                acOutputDebug, acOutputInfo, acOutputWarning, acOutputError, acOutputException);
            allLogger.Add(logger);
            return logger;
        }

        /// <summary>
        /// 是否开启Debug日志等级
        /// </summary>
        /// <param name="on"></param>
        public static void EnableLogLevelDebug(bool on)
        {
            sEnableLogLevelDebug = on;
            foreach (var logger in allLogger)
            {
                logger.EnableDebug(on);
            }
        }

        /// <summary>
        /// 是否开启Info日志等级
        /// </summary>
        /// <param name="on"></param>
        public static void EnableLogLevelInfo(bool on)
        {
            sEnableLogLevelInfo = on;
            foreach (var logger in allLogger)
            {
                logger.EnableInfo(on);
            }
        }
    }
}
